//
//  SATrialVersionView.m
//  saasRetail
//
//  Created by mac on 2023/6/24.
//   expirationPayment

#import "SATrialVersionView.h"
#import "SAUserExpireModel.h"
#import "SALoginVC.h"

@interface SATrialVersionView ()

@property (nonatomic, strong) SAUserExpireModel *expireModel;

@end

@implementation SATrialVersionView

-(instancetype)initWithFrame:(CGRect)frame AndModel:(SAUserExpireModel *)model {
    if (self = [super initWithFrame:frame]) {
        self.expireModel = model;
        [self initUI];
    }
    return self;
}


#pragma mark - event
-(void)clickedBgBtn {
    if ([self.expireModel.termType isEqualToString:@"3"]) {
        return;
    }
    [self removeFromSuperview];
}

-(void)clickedPayBtn {
    !self.payBlock ?: self.payBlock();
}

#pragma mark - initUI
-(void)initUI {
    
    UIButton *bgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgBtn.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    [bgBtn addTarget:self action:@selector(clickedBgBtn) forControlEvents:UIControlEventTouchUpInside];
    bgBtn.backgroundColor = kColor(0, 0, 0, 0.6);
    [self addSubview:bgBtn];
    
    UIView *bgView = [UIView new];
    bgView.frame = CGRectMake(kScaleNum(30), (kScreenHeight - kScaleNum(440))/2, kScreenWidth - kScaleNum(60), kScaleNum(440));
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 18;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - kScaleNum(60), kScaleNum(211))];
    imageV.image = [UIImage imageNamed:@"SATrial_pay"];
    [bgView addSubview:imageV];
    
    if (![self.expireModel.termType isEqualToString:@"3"]) {
        UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        closeBtn.frame = CGRectMake(kScreenWidth - kScaleNum(100), 0, kScaleNum(40), kScaleNum(40));
        [closeBtn addTarget:self action:@selector(clickedBgBtn) forControlEvents:UIControlEventTouchUpInside];
        [closeBtn setTitle:@"X" forState:UIControlStateNormal];
        [closeBtn setTitleColor:kColor(248, 112, 79, 1) forState:UIControlStateNormal];
        closeBtn.titleLabel.font = kFont(20);
        [bgView addSubview:closeBtn];
    }

    UILabel *trialLab = [[UILabel alloc] initWithFrame:CGRectMake(0, kScaleNum(211), kScreenWidth - kScaleNum(60), kScaleNum(90))];
    trialLab.text = @"试用版本";
    trialLab.font = kFont(30);
    trialLab.textColor = [UIColor orangeColor];
    trialLab.textAlignment = NSTextAlignmentCenter;
    [bgView addSubview:trialLab];
    
    UILabel *tipLab = [[UILabel alloc] initWithFrame:CGRectMake(0, kScaleNum(301), kScreenWidth - kScaleNum(60), kScaleNum(38))];
    tipLab.text = [NSString stringWithFormat:@"您的软件为试用版本，请您及时付款\n如有问题请联系客服：%@",self.expireModel.hotline];
    tipLab.font = kBFont(15);
    tipLab.textColor = kBlackColor;
    tipLab.textAlignment = NSTextAlignmentCenter;
    tipLab.numberOfLines = 0;
    [bgView addSubview:tipLab];
    
    UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    payBtn.frame = CGRectMake((kScreenWidth - kScaleNum(261))/2, kScaleNum(370), kScaleNum(201), kScaleNum(44));
    [payBtn addTarget:self action:@selector(clickedPayBtn) forControlEvents:UIControlEventTouchUpInside];
    [payBtn setBackgroundImage:[UIImage imageNamed:@"SATrial_toPay"] forState:UIControlStateNormal];
    [bgView addSubview:payBtn];
}

@end
